package com.metaera.app.ui.adapters.navigator;

import android.content.Context;
import android.graphics.Color;

import com.metaera.app.widget.ScaleTransitionPagerTitleView;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.List;

import androidx.viewpager.widget.ViewPager;

public class FlashNewsNavigatorAdapter extends CommonNavigatorAdapter {

    private final ViewPager    mViewPager;
    private final List<String> mDataList;

    public FlashNewsNavigatorAdapter(ViewPager viewPager, List<String> dataList) {
        this.mViewPager = viewPager;
        this.mDataList = dataList;
    }

    @Override
    public int getCount() {

        return mDataList == null ? 0 : mDataList.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, final int index) {
        // 需要知道每个标题View是什么样式的
        SimplePagerTitleView simplePagerTitleView = new ScaleTransitionPagerTitleView(context);
        simplePagerTitleView.setText(mDataList.get(index));
        simplePagerTitleView.setNormalColor(Color.parseColor("#A0A0A9"));
        simplePagerTitleView.setSelectedColor(Color.parseColor("#000000"));
        simplePagerTitleView.setTextSize(20);
        // 这里直接设置点击事件来切换ViewPager
        simplePagerTitleView.setOnClickListener(v -> mViewPager.setCurrentItem(index));
        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        return null;
    }

    @Override
    public float getTitleWeight(Context context, int index) {
        if (index == 0) {
            return 2.0f;
        } else if (index == 1) {
            return 1.2f;
        } else {
            return 1.0f;
        }
    }

}
